<!DOCTYPE html>
<html lang="zh-hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}Django博客{% endblock %}</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
        <div class="container">
            <a class="navbar-brand" href="{% url 'home' %}">Django博客</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'home' %}">首页</a>
                    </li>
                    {% for category in categories %}
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'category' category.name|slugify %}">{{ category.name }}</a>
                    </li>
                    {% endfor %}
                </ul>
                <ul class="navbar-nav">
                    {% if user.is_authenticated %}
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'post_create' %}">发布文章</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#">{{ user.username }}</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'logout' %}">退出</a>
                    </li>
                    {% else %}
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'login' %}">登录</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{% url 'register' %}">注册</a>
                    </li>
                    {% endif %}
                </ul>
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        <!-- 消息提示 -->
        {% if messages %}
            {% for message in messages %}
                <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                    {{ message }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                </div>
            {% endfor %}
        {% endif %}

        <!-- 主内容区 -->
        <div class="row">
            <div class="col-md-8">
                {% block content %}{% endblock %}
            </div>
            <div class="col-md-4">
                <!-- 侧边栏 -->
                <div class="card mb-4">
                    <div class="card-header">
                        搜索
                    </div>
                    <div class="card-body">
                        <form method="GET" action="{% url 'home' %}">
                            <div class="input-group">
                                <input type="text" class="form-control" name="search" placeholder="搜索文章...">
                                <button class="btn btn-outline-secondary" type="submit">
                                    <i class="fa fa-search"></i>
                                </button>
                            </div>
                        </form>
                    </div>
                </div>

                <div class="card mb-4">
                    <div class="card-header">
                        分类
                    </div>
                    <div class="card-body">
                        <ul class="list-group">
                            {% for category in categories %}
                            <li class="list-group-item d-flex justify-content-between align-items-center">
                                <a href="{% url 'category' category.name|slugify %}">{{ category.name }}</a>
                                <span class="badge bg-primary rounded-pill">{{ category.post_set.count }}</span>
                            </li>
                            {% endfor %}
                        </ul>
                    </div>
                </div>

                <div class="card mb-4">
                    <div class="card-header">
                        热门标签
                    </div>
                    <div class="card-body">
                        {% for tag in tags %}
                        <a href="{% url 'tag' tag.name|slugify %}" class="badge bg-secondary text-decoration-none m-1">
                            {{ tag.name }}
                        </a>
                        {% endfor %}
                    </div>
                </div>

                <div class="card">
                    <div class="card-header">
                        热门文章
                    </div>
                    <div class="card-body">
                        <ul class="list-group">
                            {% for post in popular_posts %}
                            <li class="list-group-item">
                                <a href="{{ post.get_absolute_url }}">{{ post.title }}</a>
                                <div class="text-muted small">
                                    <i class="fa fa-eye"></i> {{ post.views }} 次阅读
                                </div>
                            </li>
                            {% endfor %}
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <footer class="bg-light text-center text-lg-start mt-5">
        <div class="container p-4">
            <div class="row">
                <div class="col-lg-6 col-md-12 mb-4 mb-md-0">
                    <h5 class="text-uppercase">Django博客</h5>
                    <p>
                        一个基于Django的现代化博客系统
                    </p>
                </div>
                <div class="col-lg-6 col-md-12 mb-4 mb-md-0">
                    <h5 class="text-uppercase">关注我们</h5>
                    <div class="d-flex justify-content-center">
                        <a href="#" class="btn btn-outline-dark btn-floating m-1" role="button">
                            <i class="fa fa-weibo"></i>
                        </a>
                        <a href="#" class="btn btn-outline-dark btn-floating m-1" role="button">
                            <i class="fa fa-wechat"></i>
                        </a>
                        <a href="#" class="btn btn-outline-dark btn-floating m-1" role="button">
                            <i class="fa fa-github"></i>
                        </a>
                    </div>
                </div>
            </div>
        </div>
        <div class="text-center p-3 bg-dark text-white">
            © 2025 Django博客版权所有
        </div>
    </footer>

    <script>
        // 简单的JavaScript功能
        document.addEventListener('DOMContentLoaded', function() {
            // 导航栏滚动效果
            window.addEventListener('scroll', function() {
                const navbar = document.querySelector('.navbar');
                if (window.scrollY > 50) {
                    navbar.classList.add('shadow');
                } else {
                    navbar.classList.remove('shadow');
                }
            });
        });
    </script>
</body>
</html>